namespace SimpleWebServices
{
    using System;
    using System.Globalization;
    using System.Xml.Serialization;

    public sealed class XmlRootDecorationTest<T> : ITestExpectation
    {
        public string Name
        {
            get;
            set;
        }

        public string Namespace
        {
            get;
            set;
        }

        public bool Check()
        {
            XmlRootAttribute attribute = Attribute.GetCustomAttribute(typeof(T), typeof(XmlRootAttribute), false) as XmlRootAttribute;

            if (null == attribute)
            {
                throw new TestException(string.Format(CultureInfo.InvariantCulture, "{0} is not decorated with [XmlRoot].", typeof(T).Name));
            }
            else if (this.Name != attribute.ElementName)
            {
                throw new TestException(string.Format(CultureInfo.InvariantCulture, "{0} is not decorated with [XmlRoot(\"{1}\")].", typeof(T).Name, this.Name));
            }
            else if (this.Namespace != attribute.Namespace)
            {
                throw new TestException(string.Format(CultureInfo.InvariantCulture, "{0} is not decorated with [XmlRoot(\"{1}\", \"{2}\")].", typeof(T).Name, this.Name, this.Namespace));
            }

            return true;
        }
    }
}